package com.lvmama.task.common.vo;


import com.lvmama.comm.pet.po.pub.TaskResult;
import com.lvmama.task.common.utils.TaskUtil;

import java.io.Serializable;
import java.util.Date;

/**
 * Created by IntelliJ IDEA.<p/>
 * User: troy-kou<p/>
 * Date: 14-1-3<p/>
 * Time: 上午10:25<p/>
 * Email:kouhongyu@163.com<p/>
 */
public class Task implements Serializable, Cloneable {

    private static final long serialVersionUID = -4317240365577039061L;

    /**
     * 主键
     */
    private Long taskId;
    /**
     * 任务名称
     */
    private String taskName;
    /**
     * 地址
     */
    private String webServiceUrl;
    /**
     * 请求类型
     */
    private TASK_REQUEST_TYPE requestType;
    /**
     * 计划时间
     */
    private Date planTime;
    /**
     * 执行周期
     */
    private String cycle;
    /**
     * 周期尺度
     */
    private Long cycleDimension;
    /**
     * 每周几执行
     */
    private String week;
    /**
     * 任务状态
     */
    private String status;
    /**
     * 任务描述
     */
    private String description;
    /**
     * 是否启用
     */
    private String available;
    /**
     * 参数
     */
    private String parameter;
    /**
     * 创建时间
     */
    private Date createTime;
    /**
     * 下次运行时间
     */
    private Date nextRunTime;
    /**
     * 上次运行结果(新)
     */
    private TaskResult.RUN_STATUS lastRunStatus;
    /**
     * 上次运行时间
     */
    private Date lastTime;
    /**
     * 上次耗时
     */
    private Long lastTimeConsuming;
    /**
     * Cron表达式
     */
    private String cronExpression;
    /**
     * 调度节点
     */
    private String jobNode;
    /**
     * 超时时间
     */
    private Integer soTimeout;
    /**
     * 环境标识
     */
    private String owner;

    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public Long getTaskId() {
        return taskId;
    }

    public void setTaskId(Long taskId) {
        this.taskId = taskId;
    }

    public String getTaskName() {
        return taskName;
    }

    public void setTaskName(String taskName) {
        this.taskName = taskName;
    }

    public String getWebServiceUrl() {
        return webServiceUrl;
    }

    public void setWebServiceUrl(String webServiceUrl) {
        this.webServiceUrl = webServiceUrl;
    }

    public TASK_REQUEST_TYPE getRequestType() {
        return requestType;
    }

    public void setRequestType(TASK_REQUEST_TYPE requestType) {
        this.requestType = requestType;
    }

    public Date getPlanTime() {
        return planTime;
    }

    public void setPlanTime(Date planTime) {
        this.planTime = planTime;
    }

    public Date getNextRunTime() {
        return nextRunTime;
    }

    public void setNextRunTime(Date nextRunTime) {
        this.nextRunTime = nextRunTime;
    }

    public String getCycle() {
        return cycle;
    }

    public void setCycle(String cycle) {
        this.cycle = cycle;
    }

    public String getWeek() {
        return week;
    }

    public void setWeek(String week) {
        this.week = week;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getAvailable() {
        return available;
    }

    public void setAvailable(String available) {
        this.available = available;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getParameter() {
        return parameter;
    }

    public void setParameter(String parameter) {
        this.parameter = parameter;
    }

    public Long getCycleDimension() {
        return cycleDimension;
    }

    public void setCycleDimension(Long cycleDimension) {
        this.cycleDimension = cycleDimension;
    }

    public Date getLastTime() {
        return lastTime;
    }

    public void setLastTime(Date lastTime) {
        this.lastTime = lastTime;
    }

    public String getCronExpression() {
        return cronExpression;
    }

    public void setCronExpression(String cronExpression) {
        this.cronExpression = cronExpression;
    }

    public TaskResult.RUN_STATUS getLastRunStatus() {
        return lastRunStatus;
    }

    public void setLastRunStatus(TaskResult.RUN_STATUS lastRunStatus) {
        this.lastRunStatus = lastRunStatus;
    }

    public String getJobNode() {
        return jobNode;
    }

    public void setJobNode(String jobNode) {
        this.jobNode = jobNode;
    }

    public Integer getSoTimeout() {
        return soTimeout;
    }

    public void setSoTimeout(Integer soTimeout) {
        this.soTimeout = soTimeout;
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    public Long getLastTimeConsuming() {
        return lastTimeConsuming;
    }

    public void setLastTimeConsuming(Long lastTimeConsuming) {
        this.lastTimeConsuming = lastTimeConsuming;
    }

    public String getLastTimeConsumingFormat(){
        return TaskUtil.calculateTimeConsumingFormat(lastTimeConsuming);
    }
    /**
     * 周
     */
    public enum WEEK {
        SUNDAY("周日"),
        MONDAY("周一"),
        TUESDAY("周二"),
        WEDNESDAY("周三"),
        THURSDAY("周四"),
        FRIDAY("周五"),
        SATURDAY("周六");

        private String cnName;

        WEEK(String name) {
            this.cnName = name;
        }

        public String getCode() {
            return this.name();
        }

        public String getCnName() {
            return this.cnName;
        }

        public static String getCnName(String code) {
            for (WEEK item : WEEK.values()) {

                if (item.getCode().equals(code)) {
                    return item.getCnName();
                }
            }
            return code;
        }

        @Override
        public String toString() {
            return this.name();
        }
    }


    /**
     * 任务周期
     */
    public enum TASK_CYCLE {
        SECOND("秒"),
        MINUTE("分钟"),
        HOURS("小时"),
        DAY("天"),
        WEEK("周"),
        MONTH("月"),
        YEAR("年"),
        CRON("cron");

        private String cnName;

        TASK_CYCLE(String name) {
            this.cnName = name;
        }

        public String getCode() {
            return this.name();
        }

        public String getCnName() {
            return this.cnName;
        }

        public static String getCnName(String code) {
            for (TASK_CYCLE item : TASK_CYCLE.values()) {

                if (item.getCode().equals(code)) {
                    return item.getCnName();
                }
            }
            return code;
        }

        @Override
        public String toString() {
            return this.name();
        }
    }

    /**
     * 任务状态
     */
    public enum TASK_STATUS {
        WAIT("等待"),
        RUN("运行"),
        END("结束"),;

        private String cnName;

        TASK_STATUS(String name) {
            this.cnName = name;
        }

        public String getCode() {
            return this.name();
        }

        public String getCnName() {
            return this.cnName;
        }

        public static String getCnName(String code) {
            for (TASK_STATUS item : TASK_STATUS.values()) {

                if (item.getCode().equals(code)) {
                    return item.getCnName();
                }
            }
            return code;
        }

        @Override
        public String toString() {
            return this.name();
        }
    }

    /**
     * 任务是否启用
     */
    public enum TASK_AVAILABLE {
        ENABLE("启用"),
        DISABLE("停用");

        private String cnName;

        TASK_AVAILABLE(String name) {
            this.cnName = name;
        }

        public String getCode() {
            return this.name();
        }

        public String getCnName() {
            return this.cnName;
        }

        public static String getCnName(String code) {
            for (TASK_AVAILABLE item : TASK_AVAILABLE.values()) {

                if (item.getCode().equals(code)) {
                    return item.getCnName();
                }
            }
            return code;
        }

        @Override
        public String toString() {
            return this.name();
        }


    }

    /**
     * 请求类型
     */
    public enum TASK_REQUEST_TYPE {
        WEB_SERVICE("WEB_SERVICE"),
        RESTful("RESTful");


        private String cnName;

        TASK_REQUEST_TYPE(String name) {
            this.cnName = name;
        }

        public String getCode() {
            return this.name();
        }

        public String getCnName() {
            return this.cnName;
        }

        public static String getCnName(String code) {
            for (TASK_REQUEST_TYPE item : TASK_REQUEST_TYPE.values()) {

                if (item.getCode().equals(code)) {
                    return item.getCnName();
                }
            }
            return code;
        }

        @Override
        public String toString() {
            return this.name();
        }

    }
}
